﻿#include "mydn.h"
#include "mydnapp.h"
#include "localstorage.h"

CMydnApp::CMydnApp()
{
	
}

CMydnApp::~CMydnApp()
{
	
}

NPError CMydnApp::New(NPMIMEType pluginType, NPP instance, uint16_t mode 
					  , int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
{
	if(strcmp((char *)pluginType, "application/x-mydn-localstorage") == 0)
	{
		printf("[CMydnApp::New] new application/x-mydn-localstorage\n");
		instance->pdata = gpnpf->createobject(instance, (NPClass *)&CLocalStorage::Object);
	}
	return NPERR_NO_ERROR;
}

NPError CMydnApp::Destroy(NPP instance, NPSavedData** save)
{
	if(NULL != instance->pdata && NULL != gpnpf)
	{
		gpnpf->releaseobject((NPObject *)instance->pdata);
	}

	return NPERR_NO_ERROR;
}

NPError CMydnApp::GetValue(NPP instance, NPPVariable variable, void *ret_value)
{
	switch(variable) 
	{
	default:
		return NPERR_GENERIC_ERROR;
	case NPPVpluginNameString:
		*((char **)ret_value) = (char *)"Mydn";
		break;
	case NPPVpluginDescriptionString:
		*((char **)ret_value) = (char *)"<a href=\"www.yunjie.org\">yuanjie.org</a> plugin.";
		break;
	case NPPVpluginScriptableNPObject:
		gpnpf->retainobject((NPObject *)instance->pdata);
		*((NPObject **)ret_value) = (NPObject *)instance->pdata;
		break;
	case NPPVpluginNeedsXEmbed:
		// https://developer.mozilla.org/en/XEmbed_Extension_for_Mozilla_Plugins
		// 如果设为PR_FALSE测linux-chrome不能正常工作
#if defined(XP_UNIX)
		*((PRBool *)ret_value) = PR_TRUE;
#else
		*((PRBool *)ret_value) = PR_FALSE;
#endif
		break;
	}
	return NPERR_NO_ERROR;
}

